home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / text / cmanual.lzh / ACM2.lzh / Menus / Example5.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  16KB  |  407 lines

  1. /* Example5                                                             */
  2. /* This program opens a normal window to which we connect a menu strip. */
  3. /* The menu will look like this:                                        */
  4. /*                                                                      */
  5. /* Mode                                                                 */
  6. /* ------------------                                                   */
  7. /* | -> Plain       |                                                   */
  8. /* |    Bold        |                                                   */
  9. /* |    Underlined  |                                                   */
  10. /* |    Italic      |                                                   */
  11. /* ------------------                                                   */
  12. /*                                                                      */
  13. /* Exactly as Example1 except that we have changed Intuition's check-   */
  14. /* mark to our own customized "arrow". If you want to use your own      */
  15. /* image instead of Intuition's default one you need to:                */
  16. /* 1. Declare and initialize an Image structure with your requirements. */
  17. /* 2. Set the CheckMark field in the NewWindow structure to point at    */
  18. /*    your Image.                                                       */
  19.  
  20.  
  21.  
  22. #include <intuition/intuition.h>
  23.  
  24.  
  25.  
  26. struct IntuitionBase *IntuitionBase;
  27.  
  28.  
  29.  
  30. /*************************************************************************/
  31. /*                           T H E   S P O T                             */
  32. /*************************************************************************/
  33.  
  34. /* Data for the spot: */
  35. USHORT chip spot_data[]=
  36. {
  37.   0x0300,  /* 0000 0011 0000   0 : White   */
  38.   0x0180,  /* 0000 0001 1000   1 : Orange  */
  39.   0x00C0,  /* 0000 0000 1100               */
  40.   0x0060,  /* 0000 0000 0110               */
  41.   0xFFF0,  /* 1111 1111 1111               */
  42.   0xFFF0,  /* 1111 1111 1111               */
  43.   0x0060,  /* 0000 0000 0110               */
  44.   0x00C0,  /* 0000 0000 1100               */
  45.   0x0180,  /* 0000 0001 1000               */
  46.   0x0300,  /* 0000 0011 0000               */
  47. };
  48.  
  49. /* The spot's Image structure: */
  50. struct Image spot=
  51. {
  52.   0,         /* LeftEdge, 0 pixels out. */
  53.   -1,        /* TopEdge, 1 line up. */
  54.   12,        /* Width, 12 pixels wide. */
  55.   10,        /* Height, 10 lines heigh. */
  56.   1,         /* Depth, one Bitplane. */
  57.   spot_data, /* ImageData, pointer to the image data. */
  58.   0x2,       /* PlanePick, affect the Bitplane one. */
  59.   0x1,       /* PlaneOnOff, fill Bitplane zero with 1's. */
  60.   NULL,      /* NextImage, no Image structure connected to this one. */
  61. };
  62.  
  63.  
  64.  
  65. /*************************************************************************/
  66. /*                         F O U R T H   I T E M                         */
  67. /*************************************************************************/
  68.  
  69. /* The text for the fourth item: */
  70. struct IntuiText my_fourth_text=
  71. {
  72.   2,            /* FrontPen, black. */
  73.   0,            /* BackPen, not used since JAM1. */
  74.   JAM1,         /* DrawMode, do not change the background. */
  75.   CHECKWIDTH,   /* LeftEdge, CHECKWIDTH amount of pixels out. */
  76.                 /* This will leave enough space for the check mark. */
  77.   1,            /* TopEdge, 1 line down. */
  78.   NULL,         /* TextAttr, default font. */
  79.   "Italic",     /* IText, the string. */
  80.   NULL          /* NextItem, no link to other IntuiText structures. */
  81. };
  82.  
  83. /* The MenuItem structure for the fourth item: */
  84. struct MenuItem my_fourth_item=
  85. {
  86.   NULL,            /* NextItem, this is the last item in the list. */
  87.   0,               /* LeftEdge, 0 pixels out. */
  88.   30,              /* TopEdge, 30 lines down. */
  89.   150,             /* Width, 150 pixels wide. */
  90.   10,              /* Height, 10 lines high. */
  91.   ITEMTEXT|        /* Flags, render this item with text. */
  92.   ITEMENABLED|     /*        this item will be enabled. */
  93.   CHECKIT|         /*        it is an attribute item. */
  94.   HIGHCOMP,        /*        complement the colours when highlihted. */
  95.   0x00000001,      /* MutualExclude, mutualexclude the first item only. */
  96.   (APTR) &my_fourth_text, /* ItemFill, pointer to the text. */
  97.   NULL,            /* SelectFill, nothing since we complement the col. */
  98.   0,               /* Command, no command-key sequence. */
  99.   NULL,            /* SubItem, no subitem list. */
  100.   MENUNULL,        /* NextSelect, no items selected. */
  101. };
  102.  
  103.  
  104.  
  105. /*************************************************************************/
  106. /*                          T H I R D   I T E M                          */
  107. /*************************************************************************/
  108.  
  109. /* The text for the third item: */
  110. struct IntuiText my_third_text=
  111. {
  112.   2,            /* FrontPen, black. */
  113.   0,            /* BackPen, not used since JAM1. */
  114.   JAM1,         /* DrawMode, do not change the background. */
  115.   CHECKWIDTH,   /* LeftEdge, CHECKWIDTH amount of pixels out. */
  116.                 /* This will leave enough space for the check mark. */
  117.   1,            /* TopEdge, 1 line down. */
  118.   NULL,         /* TextAttr, default font. */
  119.   "Underlined", /* IText, the string. */
  120.   NULL          /* NextItem, no link to other IntuiText structures. */
  121. };
  122.  
  123. /* The MenuItem structure for the third item: */
  124. struct MenuItem my_third_item=
  125. {
  126.   &my_fourth_item, /* NextItem, linked to the fourth item. */
  127.   0,               /* LeftEdge, 0 pixels out. */
  128.   20,              /* TopEdge, 20 lines down. */
  129.   150,             /* Width, 150 pixels wide. */
  130.   10,              /* Height, 10 lines high. */
  131.   ITEMTEXT|        /* Flags, render this item with text. */
  132.   ITEMENABLED|     /*        this item will be enabled. */
  133.   CHECKIT|         /*        it is an attribute item. */
  134.   HIGHCOMP,        /*        complement the colours when highlihted. */
  135.   0x00000001,      /* MutualExclude, mutualexclude the first item only. */
  136.   (APTR) &my_third_text, /* ItemFill, pointer to the text. */
  137.   NULL,            /* SelectFill, nothing since we complement the col. */
  138.   0,               /* Command, no command-key sequence. */
  139.   NULL,            /* SubItem, no subitem list. */
  140.   MENUNULL,        /* NextSelect, no items selected. */
  141. };
  142.  
  143.  
  144.  
  145. /*************************************************************************/
  146. /*                         S E C O N D   I T E M                         */
  147. /*************************************************************************/
  148.  
  149. /* The text for the second item: */
  150. struct IntuiText my_second_text=
  151. {
  152.   2,          /* FrontPen, black. */
  153.   0,          /* BackPen, not used since JAM1. */
  154.   JAM1,       /* DrawMode, do not change the background. */
  155.   CHECKWIDTH, /* LeftEdge, CHECKWIDTH amount of pixels out. */
  156.               /* This will leave enough space for the check mark. */
  157.   1,          /* TopEdge, 1 line down. */
  158.   NULL,       /* TextAttr, default font. */
  159.   "Bold",     /* IText, the string. */
  160.   NULL        /* NextItem, no link to other IntuiText structures. */
  161. };
  162.  
  163. /* The MenuItem structure for the second item: */
  164. struct MenuItem my_second_item=
  165. {
  166.   &my_third_item,  /* NextItem, linked to the third item. */
  167.   0,               /* LeftEdge, 0 pixels out. */
  168.   10,              /* TopEdge, 10 lines down. */
  169.   150,             /* Width, 150 pixels wide. */
  170.   10,              /* Height, 10 lines high. */
  171.   ITEMTEXT|        /* Flags, render this item with text. */
  172.   ITEMENABLED|     /*        this item will be enabled. */
  173.   CHECKIT|         /*        it is an attribute item. */
  174.   HIGHCOMP,        /*        complement the colours when highlihted. */
  175.   0x00000001,      /* MutualExclude, mutualexclude the first item only. */
  176.   (APTR) &my_second_text, /* ItemFill, pointer to the text. */
  177.   NULL,            /* SelectFill, nothing since we complement the col. */
  178.   0,               /* Command, no command-key sequence. */
  179.   NULL,            /* SubItem, no subitem list. */
  180.   MENUNULL,        /* NextSelect, no items selected. */
  181. };
  182.  
  183.  
  184.  
  185. /*************************************************************************/
  186. /*                          F I R S T   I T E M                          */
  187. /*************************************************************************/
  188.  
  189. /* The text for the first item: */
  190. struct IntuiText my_first_text=
  191. {
  192.   2,          /* FrontPen, black. */
  193.   0,          /* BackPen, not used since JAM1. */
  194.   JAM1,       /* DrawMode, do not change the background. */
  195.   CHECKWIDTH, /* LeftEdge, CHECKWIDTH amount of pixels out. */
  196.               /* This will leave enough space for the check mark. */
  197.   1,          /* TopEdge, 1 line down. */
  198.   NULL,       /* TextAttr, default font. */
  199.   "Plain",    /* IText, the string. */
  200.   NULL        /* NextItem, no link to other IntuiText structures. */
  201. };
  202.  
  203. /* The MenuItem structure for the first item: */
  204. struct MenuItem my_first_item=
  205. {
  206.   &my_second_item, /* NextItem, linked to the second item. */
  207.   0,               /* LeftEdge, 0 pixels out. */
  208.   0,               /* TopEdge, 0 lines down. */
  209.   150,             /* Width, 150 pixels wide. */
  210.   10,              /* Height, 10 lines high. */
  211.   ITEMTEXT|        /* Flags, render this item with text. */
  212.   ITEMENABLED|     /*        this item will be enabled. */
  213.   CHECKIT|         /*        it is an attribute item. */
  214.   CHECKED|         /*        this item is initially selected. */
  215.   HIGHCOMP,        /*        complement the colours when highlihted. */
  216.   0xFFFFFFFE,      /* MutualExclude, mutualexclude all items except the */
  217.                    /*                first one. */
  218.   (APTR) &my_first_text, /* ItemFill, pointer to the text. */
  219.   NULL,            /* SelectFill, nothing since we complement the col. */
  220.   0,               /* Command, no command-key sequence. */
  221.   NULL,            /* SubItem, no subitem list. */
  222.   MENUNULL,        /* NextSelect, no items selected. */
  223. };
  224.  
  225.  
  226.  
  227. /*************************************************************************/
  228. /*                              M E N U                                  */
  229. /*************************************************************************/
  230.  
  231. /* The Menu structure for the first (and only) menu: */
  232. struct Menu my_menu=
  233. {
  234.   NULL,          /* NextMenu, no more menu structures. */
  235.   0,             /* LeftEdge, left corner. */
  236.   0,             /* TopEdge, for the moment ignored by Intuition. */
  237.   50,            /* Width, 50 pixels wide. */
  238.   0,             /* Height, for the moment ignored by Intuition. */
  239.   MENUENABLED,   /* Flags, this menu will be enabled. */
  240.   "Mode",        /* MenuName, the string. */
  241.   &my_first_item /* FirstItem, pointer to the first item in the list. */
  242. };
  243.  
  244.  
  245.  
  246. /* Declare a pointer to a Window structure: */ 
  247. struct Window *my_window;
  248.  
  249. /* Declare and initialize your NewWindow structure: */
  250. struct NewWindow my_new_window=
  251. {
  252.   50,            /* LeftEdge    x position of the window. */
  253.   25,            /* TopEdge     y positio of the window. */
  254.   200,           /* Width       200 pixels wide. */
  255.   100,           /* Height      100 lines high. */
  256.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  257.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  258.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  259.                  /*             user has selected the Close window gad. */
  260.   MENUPICK,
  261.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  262.   WINDOWCLOSE|   /*             Close Gadget. */
  263.   WINDOWDRAG|    /*             Drag gadget. */
  264.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  265.   WINDOWSIZING|  /*             Sizing Gadget. */
  266.   ACTIVATE,      /*             The window should be Active when opened. */
  267.   NULL,          /* FirstGadget No Custom gadgets. */
  268.  
  269.   &spot,         /* CheckMark   Use our own customized checkmark. */
  270.  
  271.   "Style Editor",/* Title       Title of the window. */
  272.   NULL,          /* Screen      Connected to the Workbench Screen. */
  273.   NULL,          /* BitMap      No Custom BitMap. */
  274.   80,            /* MinWidth    We will not allow the window to become */
  275.   30,            /* MinHeight   smaller than 80 x 30, and not bigger */
  276.   300,           /* MaxWidth    than 300 x 200. */
  277.   200,           /* MaxHeight */
  278.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  279. };
  280.  
  281.  
  282.  
  283. main()
  284. {
  285.   /* Boolean variable used for the while loop: */
  286.   BOOL close_me;
  287.  
  288.   /* Declare a variable in which we will store the IDCMP flag: */
  289.   ULONG class;
  290.   
  291.   /* If we recieve a MENUPICK event, the Code field of the message */
  292.   /* structure will contain the menu number of the first selected item. */
  293.   /* Declare a variable to store the Code value in, and an extra menu */
  294.   /* number variable: */
  295.   USHORT code, menu_number;
  296.   
  297.   /* Declare a MenuItem pointer: */
  298.   struct MenuItem *item;
  299.   
  300.   /* Declare a pointer to an IntuiMessage structure: */
  301.   struct IntuiMessage *my_message;
  302.  
  303.  
  304.  
  305.   /* Before we can use Intuition we need to open the Intuition Library: */
  306.   IntuitionBase = (struct IntuitionBase *)
  307.     OpenLibrary( "intuition.library", 0 );
  308.   
  309.   if( IntuitionBase == NULL )
  310.     exit(); /* Could NOT open the Intuition Library! */
  311.  
  312.  
  313.  
  314.   /* We will now try to open the window: */
  315.   my_window = (struct Window *) OpenWindow( &my_new_window );
  316.   
  317.   /* Have we opened the window succesfully? */
  318.   if(my_window == NULL)
  319.   {
  320.     /* Could NOT open the Window! */
  321.     
  322.     /* Close the Intuition Library since we have opened it: */
  323.     CloseLibrary( IntuitionBase );
  324.  
  325.     exit();  
  326.   }
  327.  
  328.  
  329.  
  330.   /* We have opened the window, and everything seems to be OK. */
  331.  
  332.  
  333.  
  334.   SetMenuStrip( my_window, &my_menu );
  335.   printf("Menustrip connected to window!\n");
  336.  
  337.  
  338.   close_me = FALSE;
  339.  
  340.   /* Stay in the while loop until the user has selected the Close window */
  341.   /* gadget: */
  342.   while( close_me == FALSE )
  343.   {
  344.     /* Wait until we have recieved a message: */
  345.     Wait( 1 << my_window->UserPort->mp_SigBit );
  346.  
  347.     /* As long as we collect messages sucessfully we stay in the loop: */
  348.     while(my_message=(struct IntuiMessage *) GetMsg( my_window->UserPort ))
  349.     {
  350.       /* After we have collected the message we can read it, and save any */
  351.       /* important values which we maybe want to check later: */
  352.       class = my_message->Class;
  353.       code = my_message->Code;
  354.  
  355.  
  356.       /* After we have read it we reply as fast as possible: */
  357.       /* REMEMBER! Do never try to read a message after you have replied! */
  358.       /* Some other process has maybe changed it. */
  359.       ReplyMsg( my_message );
  360.  
  361.       /* Check which IDCMP flag was sent: */
  362.       if( class == CLOSEWINDOW )
  363.         close_me=TRUE; /* The user selected the Close window gadget! */  
  364.  
  365.       if(class == MENUPICK)
  366.       {
  367.         printf("\nMenu pick!\n");
  368.         menu_number = code;
  369.         
  370.         while( menu_number != MENUNULL )
  371.         {
  372.           /* Get the address of the item: */
  373.           item = (struct MenuItem *) ItemAddress( &my_menu, menu_number );
  374.  
  375.  
  376.           /* Print out the menu number plus etc: */
  377.           printf("menu_number= %d\n", menu_number );
  378.           printf("MENUNUM = %d\n", MENUNUM(menu_number) );
  379.           printf("ITEMNUM = %d\n", ITEMNUM(menu_number) );
  380.           printf("SUBNUM  = %d\n", SUBNUM(menu_number) );
  381.  
  382.  
  383.           /* Get the following item's menu number: */
  384.           menu_number = item->NextSelect;
  385.         }
  386.       }
  387.     }
  388.   }
  389.  
  390.  
  391.  
  392.   printf("Menustrip removed from window!\n");
  393.   ClearMenuStrip( my_window );
  394.  
  395.  
  396.  
  397.   /* Close the window: */
  398.   CloseWindow( my_window );
  399.  
  400.  
  401.  
  402.   /* Close the Intuition Library since we have opened it: */
  403.   CloseLibrary( IntuitionBase );
  404.   
  405.   /* THE END */
  406. }
  407.